<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="p" value="${param}"></c:set>
<div class="easyui-layout" style="width:100%;height:100%;" fit="true">
    <div data-options="region:'center',title:'',split:true" style="height:100%;">
		<form id="form" method="post" >
			<table class="detailTable">
			
			<tr>
                <th>系统类别:</th>
                <td>
                	<%=new String(request.getParameter("typeName").getBytes("iso-8859-1"),"utf-8")%>
                </td>
            </tr>
			
    	 	<tr>
                <th>类别名称:</th>
                <td>
                	<input class="easyui-validatebox"  name="name" data-options="required:true">
                </td>
            </tr>
            
            <tr>
                <th>所属分类:</th>
                <td>
                	<select id="parentid" name="parentid" style="width:150px" data-options="panelHeight:'auto'">
		          	</select>
		          	<img class="iconImg ext-icon-cross" onclick="$('#parentid').combotree('clear');" title="清空" />
		          	（不选分类则为顶级分类）
                </td>
            </tr>
            
           	<tr>
				<th>是否首页:</th>
				<td><input name="isIndex" type="checkbox" value="1" /> </td>
			</tr>
			
			<tr>
				<th>是否显示:</th>
				<td><input name="isShow" type="checkbox" value="1" /> </td>
			</tr>
            
			<tr>
				<td align="right" colspan="2">
					<input type="button" onclick="submitForm()" class="button" value="提交" >
					<input type="button" onclick="pms.resetForm('form')" class="button" value="重置" >
				</td>
			</tr>
		</table>
		
		<input type="hidden" name="typeId" value="<%=request.getParameter("typeId")%>">
		
		<!-- 判断newsTypeId是否为空，如果为空，则是新增，不为空，则是修改  -->
		<% if ( request.getParameter("newsTypeId") != null ){ %>
		<input type="hidden" name="newsTypeId" id="newsTypeId" value="<%=request.getParameter("newsTypeId")%>"/>
		<%}%>
		
		</form>
    </div>
</div>  

<script type="text/javascript" src="<c:url value='/js/common/date.js'/>"></script>

<script>
$(function(){
	
	newsTypeId  = <%=request.getParameter("newsTypeId")%>;
	if(newsTypeId!=null){
		//更新，获取数据并显示
			var param = {"newsTypeId":newsTypeId};
				$.pmsAjax({
				url:'<c:url value="/newstype/searchEmBNewsType.do"/>',
				data:param,
				success:function(data){
					if(data){
						$('#form').form('load', data); 
					}else{
						alertError(data.resultMessage);
					}
				}
			});
			
	}else{
		//新增，设置默认值
		$('#publishDate').val(getDate());
	}
	
	var parentid;
	parentid = $('#parentid').combotree({
		url:'<c:url value="/newstype/searchEmBNewsTypeByParentIdToComboTree.do"/>',
		onLoadSuccess:function(node,data){
			$('#parentid').combotree('setValue',<%=request.getParameter("parentid") %>);
		}
	});
});

function submitForm(){
	if(newsTypeId!=null){
		url = '<c:url value="/newstype/updateEmBNewsType.do"/>';
	}else{
		url = '<c:url value="/newstype/insertNewsType.do"/>';
	}
	
	if( $('#parentid').combotree('getValue') == newsTypeId && $('#parentid').combotree('getValue') != null){
		alertError('当前分类与目标分类不能相同');
		return false;
	}
	
	var queryParams = {};
	if($('#parentid').combotree('getValue') == null){
		queryParams = {parentid:0};
	}
	
	
	$('#form').form('submit', {
	    url:url,
	    queryParams:queryParams,
	    onSubmit: function(param){
	    	if(!$("#form").form('validate')){
	    		return false;
	    	}
	    }, 
	    success:function(data){
		    var ret = eval("("+data+")");
	     	if(ret.result){
	     		alertShow("数据处理成功");
	     		$("#w_form").dialog('close');
	     		tbl.treegrid('reload');
		    }else{
		    	alertError(ret.resultMessage);
			}
	    }
	});
}
</script>
